﻿using App_1.Entites;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;

namespace App_1.Data.Mappings
{
    public class CharacterConfiguration : IEntityTypeConfiguration<Character>
    {
        public void Configure(EntityTypeBuilder<Character> builder)
        {
            builder.Property(character => character.Nickname).HasMaxLength(20);
            builder.Property(character => character.Classes).HasMaxLength(20);

            builder.HasIndex(character => character.Nickname).IsUnique();//设置唯一索引
            builder.HasOne(c => c.Player)//配置一对一或一对多的关系
                   .WithMany(p => p.characters)//方法用于配置多的一方，即Player实体有多个Character实体
                   .HasForeignKey(c => c.PlayerId);//配置外键
        }
    }
}
